﻿using Appliaction.Dto.Pinv;
using Appliaction.IAppServices.Pinv;
using AutoMapper;
using Domain.Entitys.Pinv;
using Domain.IRepositorys.Pinv;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace Appliaction.AppServices.Pinv
{
    public class PoService : IPoService
    {
        private readonly IMapper mapper;
        private readonly IPoRepository poRepository;

        public PoService(IMapper mapper,IPoRepository poRepository)
        {
            this.mapper = mapper;
            this.poRepository = poRepository;
        }
        /// <summary>
        /// 根据采购订单code查询采购明细
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public async Task<List<pinv_details>> Getdetailswherecode(string code)
        {
            return await poRepository.Getdetailswherecode(code);
        }

        /// <summary>
        /// 条件查询总条数
        /// </summary>
        /// <param name="Po_VendorName"></param>
        /// <param name="Po_Name"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public int GetPoCount(string Po_VendorName, string Po_Name, string proName)
        {
            return poRepository.GetPoCount(Po_VendorName, Po_Name,proName);
        }
        /// <summary>
        /// 分页、条件查询
        /// </summary>
        /// <param name="Po_VendorName"></param>
        /// <param name="Po_Name"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public List<Po_details_Order> GetPoFYWhere(string Po_VendorName,  string Po_Name, int currentPage, int pageSize, string proName)
        {
            return poRepository.GetPoFYWhere(Po_VendorName, Po_Name, currentPage, pageSize,proName);
        }
        /// <summary>
        /// 条件查询
        /// </summary>
        /// <param name="Po_VendorName"></param>
        /// <param name="Po_EndorCode"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<Pinv_Po> GetPoWhere(string Po_VendorName)
        {
            return poRepository.GetPoWhere(Po_VendorName);

        }
        /// <summary>
        /// 分页、条件查询2
        /// </summary>
        /// <param name="Po_Vendor_Name"></param>
        /// <param name="Po_Code"></param>
        /// <param name="Po_State"></param>
        /// <param name="Po_Rep_Id"></param>
        /// <param name="Po_depd_id"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public Task<List<Pinv_Po>> GetPoWhere(string Po_Vendor_Name, string Po_Code, int Po_State, int Po_Rep_Id, int Po_depd_id, int currentPage, int pageSize)
        {
            return poRepository.GetPoWhere(Po_Vendor_Name, Po_Code, Po_State, Po_Rep_Id, Po_depd_id, currentPage, pageSize);
        }
        /// <summary>
        /// 添加查询总条数2
        /// </summary>
        /// <param name="Po_Vendor_Name"></param>
        /// <param name="Po_Code"></param>
        /// <param name="Po_State"></param>
        /// <param name="Po_Rep_Id"></param>
        /// <param name="Po_depd_id"></param>
        /// <returns></returns>
        public int GetPoWhereCount(string Po_Vendor_Name, string Po_Code, int Po_State, int Po_Rep_Id, int Po_depd_id)
        {
            return poRepository.GetPoWhereCount(Po_Vendor_Name, Po_Code, Po_State, Po_Rep_Id, Po_depd_id);
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="pinv_Po"></param>
        /// <returns></returns>
        public Task<int> PostPoAdd(PinvOrderDetailsDto<Pinv_Po_AddDto> PinvOrderDetailsDto)
        {
            Pinv_Po po = mapper.Map<Pinv_Po>(PinvOrderDetailsDto.Pinv_Order_Dto);
            List<pinv_details> pinv_details = mapper.Map<List<pinv_details>>(PinvOrderDetailsDto.pinv_detailsAddDto);
            return poRepository.PostPoAdd(po, pinv_details);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="pinv_Po"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> PutPoDelete(PoDeleteDto pinv_Po)
        {
            Pinv_Po po = mapper.Map<Pinv_Po>(pinv_Po);
            return poRepository.PutPoDelete(po);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="pinv_Po"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> PutPoUpdate(PinvOrderDetailsDto<Pinv_PoUpdateDto> PinvOrderDetailsDto)
        {
            Pinv_Po po = mapper.Map<Pinv_Po>(PinvOrderDetailsDto.Pinv_Order_Dto);
            List<pinv_details> details = mapper.Map<List<pinv_details>>(PinvOrderDetailsDto.pinv_detailsAddDto);
            return poRepository.PutPoUpdate(po, details);
        }
        /// <summary>
        /// 根据code审核
        /// </summary>
        /// <param name="pinv_Po"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> PutPoUpdateAudit(Pinv_PoUpdateAuditDto pinv_Po)
        {
            Pinv_Po po = mapper.Map<Pinv_Po>(pinv_Po);
            return poRepository.PutPoUpdateAudit(po);
        }
        /// <summary>
        /// 根据采购订单编号已经条件查询明细
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public Task<List<pinv_details>> GetdetailswherecodeFY(string code, string procode, int unitmeas_id, int currentPage, int pageSize)
        {
            return poRepository.GetdetailswherecodeFY(code, procode, unitmeas_id, currentPage, pageSize);
        }
        /// <summary>
        /// 根据采购订单编号已经条件查询明细总条数
        /// </summary>
        /// <returns></returns>
        public int GetdetailswherecodeFYCount(string code, string procode, int unitmeas_id)
        {
            return poRepository.GetdetailswherecodeFYCount(code, procode, unitmeas_id);
        }

        public List<Po_details_Order> GetPoFYWhereAudit(string Po_VendorName, string Po_Name, int currentPage, int pageSize)
        {
            return poRepository.GetPoFYWhereAudit(Po_VendorName, Po_Name, currentPage, pageSize);
        }

        public int GetPoCountAudit(string Po_VendorName, string Po_Name)
        {
            return poRepository.GetPoCountAudit(Po_VendorName, Po_Name);
        }

        public List<Po_details_Order> Po_Details_OrdersSummary(string Po_VendorName, string Po_Name, string proName)
        {
            return poRepository.Po_Details_OrdersSummary(Po_VendorName,Po_Name,proName);
        }

        /// <summary>
        /// 采购订单撤销
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Task<int> Pinv_PoRevokeAsync(Pinv_PoRevokeDto pinv_PoRevokeDto)
        {
            Pinv_Po pinv_Po = mapper.Map<Pinv_Po>(pinv_PoRevokeDto);
            return poRepository.Pinv_PoRevokeAsync(pinv_Po);
        }
    }
}
